package com.pan.common.barrier.listener;

import com.pan.controller.animal.DogController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 监听器，在项目中遇到一个ApplicationListener，
 * 在容器初始化完成后，有一些操作需要处理一下，
 * 比如数据的加载、初始化缓存、特定任务的注册等，此时可以使用这个监听器，下面是使用方式：
 * @author by panstark
 * @description
 * @notice
 * @date 2020/11/27
 */
@Slf4j
public class InitListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        try {
            log.info("-----look at here ,after the application has started,this method will be proceed.");
            log.info("get local ip is ：" + InetAddress.getLocalHost().getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
            log.error("occur a exception!");
        }
    }
}


